package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends HelperBase{

	public NavigationHelper(ApplicationManager manager) {
		super(manager);
	}

	public void mainPage() {
		if (!onMainPage()){
			click(By.linkText("home"));
		}
	    return;    
	}

	public void groupsPage() {
		if (!onGroupPage()){
			click(By.linkText("groups"));
		}
	    return;
	}

	public void addContactPage() {
		if (!onAddContactPage()){
			click(By.linkText("add new"));
		}
	    return;
	}

	private boolean onAddContactPage() {
		if (driver.getCurrentUrl().contains("/edit.php") 
				&& driver.findElements(By.name("submit")).size()>0)
			{
				return true;
			}
			return false;}

	private boolean onGroupPage() {
		if (driver.getCurrentUrl().contains("/group.php") 
			&& driver.findElements(By.name("new")).size()>0)
		{
			return true;
		}
		return false;
	}
	
	private boolean onMainPage() {
		return driver.findElements(By.id("maintable")).size()>0;
	}

}
